package com.ljf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljf.annotation.HasPermission;
import com.ljf.dto.SupplierPageDto;
import com.ljf.dto.SupplierSaveDto;
import com.ljf.entity.Supplier;
import com.ljf.service.SupplierService;
import com.ljf.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Validated
@RequestMapping("/inventory_management/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;
    @HasPermission("inventory_management:supplier:list")
    @PostMapping("/queryPageByQo")
    public Result PageQuery(SupplierPageDto dto){
        Page<Supplier> page = supplierService.pageQuery(dto);
        return Result.success(page);
    }

    @HasPermission("inventory_management:supplier:save")
    @PostMapping("/save")
    public Result save(Supplier supplier){
        supplierService.saveSupplier(supplier);
        return Result.success();
    }

    /*修改接口*/
    @HasPermission("inventory_management:supplier:update")
    @PostMapping("/update")
    public Result updateSupplier(Supplier supplier){
        supplierService.updateSupplier(supplier);
        return Result.success();
    }
    @HasPermission("inventory_management:supplier:update")
    @GetMapping("/queryByCn")
    public Result queryByCn(Long cn){
        return Result.success(supplierService.getById(cn));
    }
    @HasPermission("inventory_management:supplier:deactivate")
    @PostMapping("/deactivate")
    public Result deactivate(Long cn){
        supplierService.deactivate(cn);
        return Result.success();
    }
}
